/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.br.imovel.converter;

import com.br.imovel.model.Modulo;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author diego
 */
@FacesConverter(value = "moduloConverter")
public class ModuloConverter implements Converter {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Modulo retorno = new Modulo();

        if (!(value.equals(""))) {

            Object[] objetoArray = new Object[2];
            objetoArray = value.split("$");

            retorno.setId(Long.parseLong(objetoArray[0].toString()));
            retorno.setNome(objetoArray[1].toString());
        }
        return retorno;
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return value.toString();
    }
}
